package com.example.studentmanager.Controller;

import com.example.studentmanager.Pojo.Student;
import com.example.studentmanager.Service.impl.Studentimpl;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "Student", value = "/stuid")
public class Selectbykey extends HttpServlet {
    private String error="输入内容有误 请输入正确的学号";
    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
res.setCharacterEncoding("utf-8");
String key=req.getParameter("studentid");
if (key!=null) {
    Studentimpl stuservice = new Studentimpl();
    List<Student> list = new ArrayList<>();
    list = stuservice.queryByKey(key);
    RequestDispatcher ds= req.getRequestDispatcher("./querykey.jsp");
    req.setAttribute("list",list);
    ds.forward(req,res);
}else {
    System.out.println("查询失败");
    RequestDispatcher ds= req.getRequestDispatcher("./404.jsp");
    req.setAttribute("error",error);
    ds.forward(req,res);
}

    }
}
